/**
 * 〈〉
 *
 * @author 王青杰
 * @create 2018-08-0820:31
 * @since 1.0.0
 */
package org.wlgzs.website.wlgzsoffice.service.impl;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.wlgzs.website.wlgzsoffice.dao.AssessDao;
import org.wlgzs.website.wlgzsoffice.entity.TbAssess;
import org.wlgzs.website.wlgzsoffice.enums.ResultEnum;
import org.wlgzs.website.wlgzsoffice.service.AssessService;
import org.wlgzs.website.wlgzsoffice.util.ResultMsg;
import java.util.*;

import javax.annotation.Resource;

@Service
public class AssessServiceImpl implements AssessService {
    @Resource
    AssessDao assessDao;
    @Override
    public ResultMsg insertAssess(TbAssess assess) {
        if(assess!=null){
           assessDao.insertSelective(assess);
            return new ResultMsg(ResultEnum.SAVE,assess);
        }
        return new ResultMsg(ResultEnum.UNSAVE);
    }

    @Override
    public ResultMsg deleteAssess(int assessId) {
        if(assessDao.selectByPrimaryKey(assessId)!=null){
            assessDao.deleteByPrimaryKey(assessId);
            PageHelper.startPage(0,10);
            List<TbAssess> assessList  = assessDao.getAllAssess();
            PageInfo pageInfo = new PageInfo(assessList);
            return new ResultMsg(ResultEnum.DELETE,pageInfo);
        }
        PageHelper.startPage(0,10);
        List<TbAssess> assessList  = assessDao.getAllAssess();
        PageInfo pageInfo = new PageInfo(assessList);
        return new ResultMsg(ResultEnum.UNDELETE,assessList);
    }

    @Override
    public ResultMsg update(TbAssess assess) {
        if(assess.getAssessId()!=0){
            if(assessDao.selectByPrimaryKey(assess.getAssessId())!=null){
                assessDao.updateByPrimaryKey(assess);
                return new ResultMsg(ResultEnum.UPDATE,assessDao.selectByPrimaryKey(assess.getAssessId()));
            }
        }
        return new ResultMsg(ResultEnum.UNUPDATE);
    }

    @Override
    public ResultMsg checkAssess(int assessId) {
        return null;
    }

    @Override
    public ResultMsg checkAllAssess(int pageNum, TbAssess assess) {
        if(assess.getAssessId()==null){
            assess.setAssessId(0);
        }
        if(assess.getAssessTitle()==null){
            assess.setAssessTitle("");
        }
        if(assess.getReleaseTime()==null){
            assess.setReleaseTime("");
        }
        PageHelper.startPage(0,10);
        List<TbAssess> assessList  = assessDao.checkAllByKey(assess.getAssessId(),assess.getReleaseTime(),assess.getAssessTitle());
        PageInfo pageInfo = new PageInfo(assessList);
        return new ResultMsg(ResultEnum.QUIRY,pageInfo);
    }
}
